package org.cbg.until;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.Border;

import com.tool.tcpimg.UIUtils;
import org.cbg.btn.TrslationBtn;
import org.cbg.entity.Collection;
import org.cbg.entity.Salegoods;
import org.cbg.panel.TraslationWantBuyDahuabiModelJpanel;
import org.cbg.panel.TraslationWantBuyDaojuModelJpanel;
import org.come.until.CutButtonImage;
import org.come.until.MessagrFlagUntil;
import org.come.until.cbgSrcollPanelUI;

 

public class TraslationTableUntil extends JPanel {

    TraslationWantBuyDahuabiModelJpanel traslationWantBuyDahuabiModelJpanel;



    public TraslationTableUntil() {
        // TODO Auto-generated constructor stub
    }

    /**
     * 自行生成结果展示
     * 
     * @param jScrollPane
     * @param geshu
     *            多少条数据
     */
    public static void TableModel(JScrollPane jScrollPane, int geshu) {
        /**
         * 表格
         */
        JPanel jPanel = new JPanel();
        jPanel.setBackground(null);
        jPanel.setOpaque(false);
        jPanel.setBorder(null);
        jPanel.setLayout(null);
        jScrollPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(jScrollPane));
        jScrollPane.setViewportView(jPanel);
        jScrollPane.setOpaque(false);
        jScrollPane.setBorder(null);
        jScrollPane.getViewport().setOpaque(false);
        Border js = BorderFactory.createEmptyBorder();
        jScrollPane.setBorder(js);
        jScrollPane.setVerticalScrollBarPolicy(20);
        jScrollPane.setHorizontalScrollBarPolicy(31);
        /**
         * 设置监听
         * 
         * @author Asus
         * 
         */
        class MListener extends MouseAdapter {
            @Override
            public void mouseEntered(MouseEvent e) {
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(UIUtils.COLOR_cbg5);
                btn.setOpaque(true);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                // TODO Auto-generated method stub
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(null);
                btn.setOpaque(false);
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

            }
        }
        for (int i = 0; i < geshu; i++) {
            TraslationWantBuyDaojuModelJpanel traslationWantBuyDahuabiModelJpanel = new TraslationWantBuyDaojuModelJpanel();
            traslationWantBuyDahuabiModelJpanel.setBounds(0, i * 62, 740, 60);
            traslationWantBuyDahuabiModelJpanel.setName("第" + i + "个面板");
            MListener m = new MListener();
            traslationWantBuyDahuabiModelJpanel.addMouseListener(m);
            jPanel.add(traslationWantBuyDahuabiModelJpanel);
        }
        jPanel.setPreferredSize(new Dimension(760, 62 * geshu));
        jScrollPane.updateUI();
        jScrollPane.invalidate();
        jScrollPane.validate();
        jScrollPane.repaint();
    }

    /**
     * 根据查询条件查询结果展示
     * 
     * @param jScrollPane
     * @param salegoodsList
     *            多少条数据
     */
    public static void setTableModel(JScrollPane jScrollPane, List<Salegoods> salegoodsList) {
        /**
         * 表格
         */
        JPanel view = (JPanel) jScrollPane.getViewport().getView();
        view.removeAll();
        view.repaint();
        jScrollPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(jScrollPane));
        jScrollPane.setViewportView(view);
        jScrollPane.setOpaque(false);
        jScrollPane.setBorder(null);
        jScrollPane.getViewport().setOpaque(false);
        Border js = BorderFactory.createEmptyBorder();
        jScrollPane.setBorder(js);
        jScrollPane.setVerticalScrollBarPolicy(20);
        jScrollPane.setHorizontalScrollBarPolicy(31);
        /**
         * 设置监听
         * 
         * @author Asus
         * 
         */
        class MListener extends MouseAdapter {
            @Override
            public void mouseEntered(MouseEvent e) {
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(UIUtils.COLOR_cbg5);
                btn.setOpaque(true);
                MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                // TODO Auto-generated method stub
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(null);
                btn.setOpaque(false);
                MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

            }
        }
        for (int i = 0; i < salegoodsList.size(); i++) {
            TraslationWantBuyDaojuModelJpanel traslationWantBuyDaojuModelJpanel = new TraslationWantBuyDaojuModelJpanel(
                    salegoodsList.get(i));
            traslationWantBuyDaojuModelJpanel.setBounds(0, i * 62, 740, 60);
            traslationWantBuyDaojuModelJpanel.setName("第" + i + "个新" + i + "面板");
            MListener m = new MListener();
            traslationWantBuyDaojuModelJpanel.addMouseListener(m);
            view.add(traslationWantBuyDaojuModelJpanel);
        }
        view.setPreferredSize(new Dimension(760, 62 * salegoodsList.size()));
        jScrollPane.updateUI();
        jScrollPane.invalidate();
        jScrollPane.validate();
        jScrollPane.repaint();
    }

    /**
     * 根据查询条件查询结果展示（收藏）
     * 
     * @param jScrollPane
     * @param collections
     *            多少条数据
     */
    public static void setShoucangTableModel(JScrollPane jScrollPane, List<Collection> collections) {
        /**
         * 表格
         */
        JPanel view = (JPanel) jScrollPane.getViewport().getView();
        view.removeAll();
        view.repaint();
        jScrollPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(jScrollPane));
        jScrollPane.setViewportView(view);
        jScrollPane.setOpaque(false);
        jScrollPane.setBorder(null);
        jScrollPane.getViewport().setOpaque(false);
        Border js = BorderFactory.createEmptyBorder();
        jScrollPane.setBorder(js);
        jScrollPane.setVerticalScrollBarPolicy(20);
        jScrollPane.setHorizontalScrollBarPolicy(31);
        /**
         * 设置监听
         * 
         * @author Asus
         * 
         */
        class MListener extends MouseAdapter {
            @Override
            public void mouseEntered(MouseEvent e) {
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(UIUtils.COLOR_cbg5);
                btn.setOpaque(true);
                MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                // TODO Auto-generated method stub
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(null);
                btn.setOpaque(false);
                MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

            }
        }
        for (int i = 0; i < collections.size(); i++) {
            if ("大话币".equals(collections.get(i).getSalename())) {
                TraslationWantBuyDahuabiModelJpanel traslationWantBuyDahuabiModelJpanel = new TraslationWantBuyDahuabiModelJpanel(
                        collections.get(i));
                traslationWantBuyDahuabiModelJpanel.setBounds(0, i * 62, 740, 60);
                traslationWantBuyDahuabiModelJpanel.setName("第" + i + "个新" + i + "面板");
                MListener m = new MListener();
                traslationWantBuyDahuabiModelJpanel.addMouseListener(m);
                view.add(traslationWantBuyDahuabiModelJpanel);
            } else {
                TraslationWantBuyDaojuModelJpanel traslationWantBuyDaojuModelJpanel = new TraslationWantBuyDaojuModelJpanel(
                        collections.get(i));
                traslationWantBuyDaojuModelJpanel.setBounds(0, i * 62, 740, 60);
                traslationWantBuyDaojuModelJpanel.setName("第" + i + "个新" + i + "面板");
                MListener m = new MListener();
                traslationWantBuyDaojuModelJpanel.addMouseListener(m);
                view.add(traslationWantBuyDaojuModelJpanel);
            }

        }
        view.setPreferredSize(new Dimension(760, 62 * collections.size()));
        jScrollPane.updateUI();
        jScrollPane.invalidate();
        jScrollPane.validate();
        jScrollPane.repaint();
    }

    /**
     * 根据查询条件查询结果展示
     * 
     * @param jScrollPane
     * @param salegoodsList
     *            多少条数据
     */
    public static void setTableModel(JScrollPane jScrollPane, List<Salegoods> salegoodsList,
            List<BigDecimal> bigDecimalsList) {
        /**
         * 表格
         */


        JPanel view = (JPanel) jScrollPane.getViewport().getView();
        view.removeAll();
        view.repaint();
        jScrollPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(jScrollPane));
        jScrollPane.setViewportView(view);
        jScrollPane.setOpaque(false);
        jScrollPane.setBorder(null);
        jScrollPane.getViewport().setOpaque(false);
        Border js = BorderFactory.createEmptyBorder();
        jScrollPane.setBorder(js);
        jScrollPane.setVerticalScrollBarPolicy(20);
        jScrollPane.setHorizontalScrollBarPolicy(31);
        /**
         * 设置监听
         * 
         * @author Asus
         * 
         */
        class MListener extends MouseAdapter {
            @Override
            public void mouseEntered(MouseEvent e) {
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(UIUtils.COLOR_cbg5);
                btn.setOpaque(true);
                MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(null);
                btn.setOpaque(false);
                MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
            }

            @Override
            public void mouseClicked(MouseEvent e) {

            }
        }
        for (int i = 0; i < salegoodsList.size(); i++) {
            if ("大话币".equals(salegoodsList.get(i).getSalename())) {
                TraslationWantBuyDahuabiModelJpanel traslationWantBuyDahuabiModelJpanel = new TraslationWantBuyDahuabiModelJpanel(
                        salegoodsList.get(i), i);
                traslationWantBuyDahuabiModelJpanel.setBounds(0, i * 62, 740, 60);
                traslationWantBuyDahuabiModelJpanel.setName("第" + i + "个新" + i + "面板");
                MListener m = new MListener();
                traslationWantBuyDahuabiModelJpanel.addMouseListener(m);
                // jPanel.add(traslationWantBuyDahuabiModelJpanel);
                view.add(traslationWantBuyDahuabiModelJpanel);
                /**
                 * 判断是否收藏
                 */
                if (bigDecimalsList.contains(salegoodsList.get(i).getSaleid())) {
                    TrslationBtn component2 = (TrslationBtn) traslationWantBuyDahuabiModelJpanel.getComponent(2);
                    try {
                        component2.setIcons(CutButtonImage.cuts("inkImg/number/b4/scxx.png"));
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    traslationWantBuyDahuabiModelJpanel.setStateOrNo(0);
                }
            } else {
                TraslationWantBuyDaojuModelJpanel traslationWantBuyDaojuModelJpanel = new TraslationWantBuyDaojuModelJpanel(
                        salegoodsList.get(i));
                traslationWantBuyDaojuModelJpanel.setBounds(0, i * 62, 740, 60);
                traslationWantBuyDaojuModelJpanel.setName("第" + i + "个新" + i + "面板");
                MListener m = new MListener();
                traslationWantBuyDaojuModelJpanel.addMouseListener(m);
                view.add(traslationWantBuyDaojuModelJpanel);

                /**
                 * 判断是否收藏
                 */
                if(bigDecimalsList!=null) {
                    if (bigDecimalsList.contains(salegoodsList.get(i).getSaleid())) {
                        TrslationBtn component2 = (TrslationBtn) traslationWantBuyDaojuModelJpanel.getComponent(2);
                        try {
                        component2.setIcons(CutButtonImage.cuts("inkImg/number/b4/scxx.png"));
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        traslationWantBuyDaojuModelJpanel.setStateOrNo(0);
                    }
                }
            }

        }

        view.setPreferredSize(new Dimension(760, 62 * salegoodsList.size()));
        jScrollPane.updateUI();
        jScrollPane.invalidate();
        jScrollPane.validate();
        jScrollPane.repaint();
    }

}
